package org.xiaojl.config.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 系统配置加载监听器，随系统启动而启动
 */
public class SystemListener implements ServletContextListener {
	private Logger log = LoggerFactory.getLogger(SystemListener.class);
	public void contextDestroyed(ServletContextEvent arg0) {
		log.info("项目停止...");
	}

	public void contextInitialized(ServletContextEvent arg0) {
		try {
			long t1 = System.nanoTime();
			//加载系统配置
			
			//加载系统前端缓存
			
			//加载系统后台缓存
			
			
			/** 获取相关的bean，并加载对应的配置
			WebApplicationContext app = WebApplicationContextUtils.getWebApplicationContext(arg0.getServletContext());
			FrontCache frontCache = (FrontCache) app.getBean("frontCache");
			ManageCache manageCache = (ManageCache) app.getBean("manageCache");
			frontCache.loadAllCache();
			manageCache.loadAllCache();
			
			TaskManager taskManager = (TaskManager) app.getBean("taskManager");
			taskManager.start();
			*/
			log.info("系统初始化完成，耗时["+(System.nanoTime()-t1)+"]纳秒(1秒=1000毫秒；1毫秒=1000微秒；1微秒=1000纳秒)");
		} catch (Throwable e) {
			log.error("系统初始化失败："+e.getMessage());
			try {
				throw new Exception("系统初始化失败！");
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
	}

}